<template>
  <div class="partnerList">
    <div class="partnerList_top">
      <div class="into_index">首页<i class="el-icon-close"></i></div>
      <div class="current">导购结算<i class="el-icon-close"></i></div>
    </div>
    <div class="partnerList_bottom">
      <div class="partnerList_bottom_new">
        <div class="partnerList_bottom_new_goods">
          <div class="partnerList_bottom_new_goods_btn">
            <!-- <button @click="addRecommend"><i class="el-icon-trophy"></i>新增小区</button> -->
          </div>
          <div class="partnerList_bottom_new_goods_screening">
            <div class="regionSelect">
              订单类型
              <el-select
                v-model="valueType"
                @change="selectType"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </div>
            <div class="partnerList_bottom_new_goods_screening_right">
              <el-input v-model="input" clearable @input="clearInput" placeholder="请输入"></el-input>
              <button @click="handerSeach">
                <i class="el-icon-search"></i>搜索
              </button>
            </div>
          </div>
        </div>
      </div>
      <div class="partnerList_table">
        <div class="partnerList_bottom_table">
          <table>
            <tr>
              <th></th>
              <th>序号</th>
              <th>订单号</th>
              <th>导购名称</th>
              <th>买家昵称</th>
              <th>下单时间</th>
              <th>订单金额</th>
              <th>订单底价</th>
              <th>导购收入</th>
              <th>订单类型</th>
              <th>合作商名称</th>
              <!-- <th>操作</th> -->
            </tr>
            <tr v-for="(v, i) in tableList" :key="i">
              <td>
                <font
                  class="checkbox"
                  :class="{ check_active: checkBoxAll.includes(i) }"
                  @click="handlerCheckbox(i)"
                  ><i class="el-icon-check"></i
                ></font>
              </td>
              <td>{{ v.id }}</td>
              <td>{{ v.order_no }}</td>
              <td>{{ v.guide_name }}</td>
              <td>{{ v.nickname }}</td>
              <td>{{ $moment(v.create_time * 1000).format("YYYY-MM-DD") }}</td>
              <td>{{ v.amount }}</td>
              <td>{{ v.base_price }}</td>
              <td>{{ v.commission }}</td>
              <td>
                {{
                  v.type == 1
                    ? "商城订单"
                    : v.type == 2
                    ? "设计师订单"
                    : v.type == 3
                    ? "施工订单"
                    : ""
                }}
              </td>
              <td>{{ v.hzs_name }}</td>
              <!-- <td>
								<button class="editor" @click="toEdit(v.id)">详情</button>
								<button class="shelves" @click="toDel(v.id)">删除</button>
							</td> -->
            </tr>
            <tr v-if="tableList.length == 0">
              <td class="table_title" colspan="10">当前数据空空如也</td>
            </tr>
          </table>
          <div class="partnerList_bottom_page">
            <div class="partnerList_bottom_page_left">
              <div
                class="partnerList_bottom_page_left_checkAll"
                @click="handerCheckAll"
              >
                <font class="checkbox" :class="{ check_active: checkAll }"
                  ><i class="el-icon-check"></i
                ></font>
              </div>
              全选
              <!-- <button class="partnerList_bottom_page_left_btn" @click="selectDel">删除</button> -->
            </div>
            <div class="partnerList_bottom_page_right">
              <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="page"
                :page-sizes="[10, 20, 30, 40]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
                background
              >
              </el-pagination>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      cateList: [],
      cate: {},
      input: "",
      checkAll: false,
      page: 1,
      pageSize: 10,
      total: 0,
      checkBoxAll: [], // 选中的数据
      shelvesAlls: [],
      tableList: [],
      options: [
        {
          //订单类型列表
          label: "全部",
          value: "all",
        },
        {
          label: "商城订单",
          value: "shop",
        },
        {
          label: "施工订单",
          value: "builder",
        },
        {
          label: "设计订单",
          value: "design",
        },
      ],
      valueType: "", //订单类型
    };
  },
  mounted() {
    this.getEstateList();
  },

  methods: {
    getEstateList() {
      let params = {
        keyword: this.input,
        page: this.page,
        pagesize: this.pageSize,
      };
      this.$http.post("/api/root/settle/guideOrderList", params).then((res) => {
        console.log(res, "导购结算列表");
        if (res.code == 1) {
          this.tableList = res.data.data ? res.data.data : [];
          this.total = res.data.count;
        }
      });
    },

    // 清除订单搜索
    clearInput(){
      if(this.input==''){
        this.getEstateList()
      }
    },

    // 选择订单类型
    selectType() {},

    // 删除按钮
    toDel(id) {
      this.$confirm("确定删除该小区吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$http.post("/api/root/Estate/del", { id }).then((res) => {
            console.log(res, "删除结果");
            if (res.code == 1) {
              this.getEstateList();
              this.$message.success("删除成功");
            } else {
              this.$message.warning(res.msg);
            }
          });
        })
        .catch(() => {
          console.log("点击取消");
        });
    },

    // 搜索
    handerSeach() {
      this.getEstateList();
    },

    // 详情按钮
    toEdit(id) {
      this.$router.push({ name: "estateAdd", query: { id } });
    },

    // 状态选择
    statusSelectFn(e) {
      console.log(e, "状态选择");
      this.getInfoList();
    },

    // 新增资讯按钮
    addRecommend() {
      this.$router.push({ name: "estateAdd", query: {} });
    },

    // 多选
    handlerCheckbox(i) {
      console.log(i);
      let arr = this.checkBoxAll;
      if (arr.includes(i)) {
        let index = arr.indexOf(i);
        if (index != -1) {
          arr.splice(index, 1);
          this.shelvesAlls.splice(index, 1);
          if (this.checkBoxAll.length !== this.tableList.length) {
            this.checkAll = false;
          }
        }
      } else {
        this.checkBoxAll.push(i);
        this.shelvesAlls.push(this.tableList[i].id);
        if (this.checkBoxAll.length == this.tableList.length) {
          this.checkAll = true;
        }
      }
      console.log(this.shelvesAlls);
    },
    // 全选与全不选
    handerCheckAll() {
      this.checkAll = !this.checkAll;
      let arr = this.tableList.length;
      this.checkBoxAll = [];
      this.shelvesAlls = [];
      if (this.checkAll) {
        for (let i = 0; i < arr; i++) {
          this.checkBoxAll.push(i);
        }
        this.checkBoxAll.map((v) => {
          this.shelvesAlls.push(this.tableList[v].id.toString());
        });
      } else {
        this.checkBoxAll = [];
        this.shelvesAlls = [];
      }
      console.log(this.shelvesAlls);
    },

    // // 全选后的删除
    // selectDel(){
    // 	console.log(this.shelvesAlls);
    // 	let res =[...new Set(this.shelvesAlls)]; //去重
    // 	console.log(res);
    // 	let str = res.join(',');
    // 	if(this.shelvesAlls.length){
    // 		this.$confirm('此操作将删除选中项, 是否继续?', '提示', {
    // 			confirmButtonText: '确定',
    // 			cancelButtonText: '取消',
    // 			type: 'warning'
    // 		}).then(()=>{
    // 			this.$http.post('/api/root/designer/del',{id:str}).then(res=>{
    // 				console.log(res);
    // 				if(res.code==1){
    // 					this.getDesigList();
    // 					this.checkAll=false;
    // 					this.checkBoxAll=[];
    // 					this.shelvesAlls=[];
    // 					this.$message({
    // 						type:'success',
    // 						message:'删除成功'
    // 					})
    // 				}
    // 			})
    // 		})
    // 	}else{
    // 		this.$message({
    // 			type:'info',
    // 			message:'请选择要删除的项'
    // 		})
    // 	}
    // },

    handleSizeChange(val) {
      this.pageSize = val;
      this.getEstateList();
    },
    handleCurrentChange(val) {
      this.page = val;
      this.getEstateList();
    },
  },
};
</script>

<style lang="less" scoped>
@import "guideSettle.less";
</style>
